var fullscreen = {
	full: function() {
		$('aside').css('overflow', 'hidden').animate({ width: '0' }, 200).addClass('fullWin');
		$('header').css('overflow', 'hidden').animate({ height: '0' }, 200).addClass('fullWin');
		$('.right_con').animate({ 'padding-bottom': '15px' }, 200);
		if ($('.left_menu').is(':visible')) {
			$('.right_con .btnBox').animate({ left: '148px' }, 200);
		} else {
			$('.right_con .btnBox').animate({ left: '13px' }, 200);
		}
	},
	restore: function() {
		if ($('aside').hasClass('open')) {
			$('aside,header').removeAttr('style').removeClass('fullWin');
			$('aside').animate({ width: '50px' }, 200);
			$('header').animate({ height: '55px' }, 200);
			$('.right_con').animate({ 'padding-bottom': '70px' }, 200);
			if ($('.left_menu').is(':visible')) {
				$('.right_con .btnBox').animate({ left: '198px' }, 200);
			} else {
				$('.right_con .btnBox').animate({ left: '63px' }, 200);
			}
		} else {
			$('aside').css('overflow', 'visible').animate({ width: '185px' }, 200);
			$('header').css('overflow', 'visible').animate({ height: '55px' }, 200);
			$('.right_con').animate({ 'padding-bottom': '70px' }, 200);
			if ($('.left_menu').is(':visible')) {
				$('.right_con .btnBox').animate({ left: '333px' }, 200);
			} else {
				$('.right_con .btnBox').animate({ left: '198px' }, 200);
			}
		}
	}
};
var version;
$(function() {
	var userType = window.localStorage.getItem('backstage-access-userStyle');
	var asideMark = window.localStorage.getItem('aside_mark');
	var modifypwdUrl = ''; //site.interUrl+"/content_page/personalcenter/modifypwd.html?groupid=6c68aa01ba4e4fe193fadbe22ef0610e&iconid=6ecda0648be341fcb333e124b192577e&subid=6f7ca07feb1640c78ae7a4243a2947ad&menuid=703e38316e1149eb802c2cf95e88bae4";
	if (asideMark == 'open') {
		var side = '<aside class="open" style="width:50px;">';
		if ($('.btnBox').length) {
			$('.btnBox').animate({ left: $('.btnBox').offset().left - 135 }, 400);
		}
	} else {
		var side = '<aside>';
	}
	side += '<div class="left_top">&nbsp;</div>';
	// side +='<div class="left_header">';
	// side +='<div class="head_wrap">';
	// side +='<div class="head"><img src="../../img/default_head.jpg" alt="" /></div>';
	// side +='<div class="name">超级管理员</div>';
	// side +='</div>';
	side += '</div>';
	side += '<div class="menu_groups">';
	// side +='<a href="JavaScript:;"><i class="iconfont icon-tuichu"></i><span>退出</span></a>';
	// side += '</div>';
	side += '</aside>';

	var header = '<header>';
	header += '<div class="fl">';
	if (asideMark == 'open') {
		header += '<div class="shrink open"> <i class="iconfont icon-daohang1"></i> </div>';
	} else {
		header += '<div class="shrink"> <i class="iconfont icon-daohang1"></i> </div>';
	}
	header += '<div class="logo">文旅智能管控后台管理</div>';
	header += '<div class="tmenu quick"></div>';
	header += '</div>';
	header += '<div class="fr">';
	if (userType == 4) {
		header +=
			'<a class="w52 msg_nav " href="/pages/systemMessage/systemMessage-list.html?groupid=1125949158486839296&subid=1125949394030563328&menuid=1125950423941910528&fourid=1125951265344458752">&nbsp;</a>'; //<em id="unreadnum">99</em>
	}
	// header += '<a class="w52 switch_nav" href="javascript:;">&nbsp;</a>';
	var headPicUrl = window.localStorage.getItem('backstage-access-headPicUrl') || '';
	header += '<a class="w52 setting_nav" href="' + site.interUrl + 'message/backUserPwd.html" title="修改密码">&nbsp;</a>';
	if (headPicUrl && headPicUrl != 'null' && headPicUrl != 'undefined') {
		header +=
			'<div class="w52 user_info"><div class="user_icon"><img src="' +
			headPicUrl +
			'" alt="" id="userIcon" /></div>';
	} else {
		header +=
			'<div class="w52 user_info"><div class="user_icon"><img src="/img/default_head.jpg" alt="" id="userIcon" /></div>';
	}
	header += '<div class="user_other"><p class="user_name" style="margin-top:12px"></p></div>';
	header += '<div class="arrowdown"><i class="iconfont icon-androidarrowdropdown"></i>';
	header += '<div class="ticon quit_btn" onclick="quit()"> <i class="iconfont icon-tuichu"></i> 退出</div></div>';
	header += '</div>';
	// header += '<a class="ticon msg" title="消息"> <em id="unreadnum" class="hide"></em> <i class="iconfont icon-xiaoxi1"></i> </a>';
	// header += '<div class="ticon help" onclick="quit()"> <i class="iconfont icon-tuichu"></i> </div>';
	header += '</div>';
	header += '</header>';

	if (!$('body').hasClass('noaside')) {
		$('body').prepend(side);
		$('aside').after(header);
	}
	if ($('body').hasClass('noaside')) {
		$('body').prepend(header);
	}
	if ($('body').find('div.left_menu').length == 0) {
		$('header').after('<div class="left_menu hide"> <div class="sub"></div></div>');
	}
	$('.btnBox').parents('.infoBox').css('padding-bottom', '56px');
	$('.shrink').on('click', function() {
		if ($(this).hasClass('open')) {
			if ($('.btnBox').length) {
				$('.btnBox').animate({ left: $('.btnBox').offset().left + 135 }, 400);
			}
			$(window).resize();
			$('aside').animate({ width: 185 }, 400, function() {
				$('aside').removeClass('open');
				$(window).resize();
			});
			if ($('.left_menu').hasClass('hide')) {
				$('.right_con').animate({ width: $(window).width() - 185 });
			} else {
				$('.right_con').animate({ width: $(window).width() - 320 });
			}
			$(this).removeClass('open');
			$('aside').find('.head').animate({ width: 70, height: 70 }, 400);
			$('aside').find('.menu_groups a').animate({ 'padding-left': 18 }, 400);
			window.localStorage.removeItem('aside_mark');
		} else {
			if ($('.btnBox').length) {
				$('.btnBox').animate({ left: $('.btnBox').offset().left - 135 }, 400);
			}
			$('aside').animate({ width: 50 }, 400, function() {
				$(window).resize();
			});
			if ($('.left_menu').hasClass('hide')) {
				$('.right_con').animate({ width: $(window).width() - 50 });
			} else {
				$('.right_con').animate({ width: $(window).width() - 185 });
			}
			$(this).addClass('open');
			$('aside').addClass('open');
			$('aside').find('.head').animate({ width: 43, height: 43 });
			$('aside').find('.menu_groups a').animate({ 'padding-left': 14 }, 400);
			window.localStorage.setItem('aside_mark', 'open');
		}
	});

	$('.tico.full').click(function() {
		if ($(this).hasClass('open')) {
			fullscreen.restore();
			$('.right_con').removeAttr('style');
			$(this).removeClass('open');
		} else {
			fullscreen.full();
			if ($('.left_menu').hasClass('hide')) {
				$('.right_con').animate({ width: $(window).width() }, 200);
			} else {
				$('.right_con').animate({ width: $(window).width() - 135 }, 200);
			}
			$(this).addClass('open');
		}
	});
	//验证localStorage是否存在
	if (
		window.localStorage.getItem('backstage-access-token') == '' ||
		window.localStorage.getItem('backstage-access-token') == null ||
		window.localStorage.getItem('backstage-access-token') == undefined
	) {
		ly.alert('登录失效，请重新登录！', function() {
			var thisPage = window.location.href;
			window.location.href = site.interUrl + 'login.html?pageUrl=' + thisPage;
		});
	}
	//设置姓名
	if (window.localStorage.getItem('backstage-access-name')) {
		var userName = window.localStorage.getItem('backstage-access-name');
		$('.user_name').html(userName != null && userName != 'null' ? userName : '&nbsp;');
	}
	//设置角色
	if (window.localStorage.getItem('backstage-access-userStyleName') != undefined) {
		var user_role =
			window.localStorage.getItem('backstage-access-userStyleName') != null
				? window.localStorage.getItem('backstage-access-userStyleName')
				: '';
		$('.user_role').html(user_role);
	}
	ly.getMenuData();
	$(window).resize(function() {
		$('.right_con').removeAttr('style');
		var Height = $('.right_con .card').innerHeight() + 70 || $('.right_con .card').outerHeight() + 70;
		var bool = $('.right_con').height() > Height;
		if (bool) {
			$('.right_con .btnBox').css('right', '13px');
		} else {
			$('.right_con .btnBox').removeAttr('style');
		}
		$('.menu_groups').getNiceScroll().resize();
	});
	$(window).resize();
	setTimeout(function() {
		$(window).resize();
	}, 500);
});
//退出
function quit() {
	removeStorage();
	ly.toast('退出成功');
	localStorage.clear();
	setTimeout(function() {
		window.location.href = site.interUrl + 'login.html';
	}, 200);
}
//清除localStorage
function removeStorage() {
	delCookie('autoLogin');
	delCookie('userName');
	delCookie('userPass');
	delCookie('uid');
	delCookie('sdktoken');
	window.localStorage.clear();
}
//清除cookie
function delCookie(name) {
	var cval = getCookie(name);
	if (cval != null) {
		document.cookie = name + '=;path=/;expires=' + new Date(0).toGMTString();
	}
}
//获取cookie
function getCookie(cname) {
	var name = cname + '=';
	var ca = document.cookie.split(';');
	for (var i = 0; i < ca.length; i++) {
		var c = ca[i].trim();
		if (c.indexOf(name) == 0) return unescape(c.substring(name.length, c.length));
	}
	return '';
}
